package com.cennavi.function;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorDouble;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.util.Map;

/**
 * @author GongXings
 * @createTime 16 9:30
 * @description 计算cost
 *
 */
public class CostFunction extends AbstractFunction{

    @Override
    /**
     * @param
     * arg1 cost 真实值 (s-mile)*change+pirce
     * arg2 cost 集合中的最小值 min(list)
     */
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        Number real = FunctionUtils.getNumberValue(arg1, env);
        Number min  = FunctionUtils.getNumberValue(arg2, env);
        double result = (2-(real.doubleValue()/min.doubleValue()))*100;

        return new AviatorDouble(result);
    }

    @Override
    public String getName() {
        return "cost";
    }
}